package com.liu.controller;

import com.liu.service.BookService;
import com.liu.pojo.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class BookController {
@Autowired
BookService bookService;

@RequestMapping("/findAll")
public void findAll(){
    PageRequest pageable = PageRequest.of(2,3);
    Page<Book> page =bookService.getBookByPage(pageable);

    System.out.println("总页面数： "+page.getTotalPages());
    System.out.println("总记录数: "+page.getTotalElements());
    System.out.println("查询结果： "+page.getContent());
    System.out.println("当前页数: "+page.getNumber()+1);
    System.out.println("当前记录数: "+ page.getNumberOfElements());
    System.out.println("当前记录数： "+page.getSize());

}
@GetMapping("/search")
public void search(){
    List<Book> bs1 =bookService.getBookByIdAndAuthor("鲁迅",7);
    List<Book> bs2 = bookService.getBookByAuthorStartingWith("吴");
    List<Book> bs3 = bookService.getBookByIdAndName("西",8);
    List<Book> bs4 = bookService.getBookByPriceGreaterThan(30f);
    Book b =bookService.getMaxIDBook();
    System.out.println("bs1"+bs1);
    System.out.println("bs2"+bs2);
    System.out.println("bs3"+bs3);
    System.out.println("bs4"+bs4);
    System.out.println("b"+b);
}

@GetMapping("/save")
public void save(){

    Book b  = new Book();
    b.setAuthor("鲁迅");
    b.setName("呐喊");
    b.setPrice(23f);
    bookService.addBook(b);
}



}








